namespace CSharpPro._0929;

public class Demo
{
    public void TestPrint1()
    {

        Console.WriteLine("1000以内的水仙花数有：");
        for (int i = 100; i < 1000; i++)
        {
            int hundreds = i / 100;
            int tens = (i / 10) % 10;
            int units = i % 10;

            int sum = hundreds * hundreds * hundreds +
                      tens * tens * tens +
                      units * units * units;

            if (sum == i)
            {
                Console.Write(i + " ");
            }
        }

    }

    public void TestPrint2()
    {
        Console.WriteLine("\n100以内的质数有：");
        for (int num = 2; num <= 100; num++)
        {
            bool isPrime = true;
            for (int i = 2; i <= Math.Sqrt(num); i++)//检查该数字的平方根（Math.Sqrt(num)）
            {
                if (num % i == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                Console.Write(num + " ");
            }
        }
    }
}